package com.qfedu.yanglao20admin.orderlist.controller;

import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.entity.orderlist.OrderList;
import com.qfedu.yanglao20admin.orderlist.service.OrderListService;
import com.qfedu.yanglao20admin.orderlist.service.OrderListVOService;
import com.qfedu.yanglao20admin.orderlist.vo.OrderListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (OrderList)表控制层
 *
 * @author makejava
 * @since 2023-05-02 21:10:07
 */
@RestController
@RequestMapping("orderList")
@Api(tags = "订单管理")
public class OrderListController {
    /**
     * 服务对象
     */
    @Resource
    private OrderListService orderListService;
    @Resource
    private OrderListVOService orderListVOService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @ApiOperation(value = "订单列表")
    @GetMapping("page")
    public CommonResult<Page<OrderListVO>> queryByPage(OrderListVO orderList) {
        return CommonResult.success(orderListVOService.selectPage(orderList));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderList> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.orderListService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param orderList 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<OrderList> add(OrderList orderList) {
        return ResponseEntity.ok(this.orderListService.insert(orderList));
    }

    /**
     * 编辑数据
     *
     * @param orderList 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<OrderList> edit(OrderList orderList) {
        return ResponseEntity.ok(this.orderListService.update(orderList));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.orderListService.deleteById(id));
    }

}

